import {Module} from '../framework.js'
import * as UI from '../ui.js'
import * as PageEvent from "./page-event.js"

export default class PageProperty extends Module {
    constructor(disp) {
        super(disp);
        this._PID = undefined;
        this._uiPageProperty = UI.UIPageProperty();
        this._uiPageAction = UI.UIPageAction(_ => {
            console.log('a');
            this.Dispatch(PageEvent.ModifyPagePropertyEvent(this._PID));
        }, _ => {
            this.Dispatch(PageEvent.CreatePagePropertyEvent(this._PID));
        });

        this._uiTagGroup = UI.UITagGroup();
        document.body.querySelector("#ID_main_summary_tag").append(this._uiTagGroup.element);
    }

    destroy(){
        this._uiPageProperty.Release();
        this._uiPageAction.Release();
        this._uiTagGroup.Release();
    }

    Update(pConfig) {
        this._PID = pConfig.SUID;
        this._uiPageProperty.SetData(
            pConfig.name,
            pConfig.modifyTime.toDateString(),
            pConfig.brief
        );

        this._uiTagGroup.Remove();
        this._uiTagGroup.Add(pConfig.tags);
    }
}

